#pragma once
#include "nocopy.h"
#include <string>

enum
{
    INFO,
    ERROR,
    FATAL,
    DEBUG
};
#ifdef DEBUGER
#define LOG_INFO(LogFormat, ...)                       \
    do                                                 \
    {                                                  \
        Logger *log = Logger::instance();              \
        log->SetLevel(INFO);                           \
        char buf[1024];                                \
        snprintf(buf, 1024, LogFormat, ##__VA_ARGS__); \
        log->log(buf);                                 \
    } while (0)
#else
#define LOG_INFO(LogFormat, ...)
#endif
#define LOG_ERROR(LogFormat, ...)                      \
    do                                                 \
    {                                                  \
        Logger *log = Logger::instance();              \
        log->SetLevel(ERROR);                          \
        char buf[1024];                                \
        snprintf(buf, 1024, LogFormat, ##__VA_ARGS__); \
        log->log(buf);                                 \
    } while (0)
#define LOG_FATAL(LogFormat, ...)                      \
    do                                                 \
    {                                                  \
        Logger *log = Logger::instance();              \
        log->SetLevel(FATAL);                          \
        char buf[1024];                                \
        snprintf(buf, 1024, LogFormat, ##__VA_ARGS__); \
        log->log(buf);                                 \
        exit(-1);                                      \
    } while (0)
#ifdef DEBUGER
#define LOG_DEBUGER(LogFormat, ...)                       \
    do                                                 \
    {                                                  \
        Logger *log = Logger::instance();              \
        log->SetLevel(DEBUG);                           \
        char buf[1024];                                \
        snprintf(buf, 1024, LogFormat, ##__VA_ARGS__); \
        log->log(buf);                                 \
    } while (0)
#else
#define LOG_DEBUGER(LogFormat, ...)
#endif

// 使用宏定义日志接口

class Logger : nocopyable // 日志类
{
public:
    static Logger *instance();
  
    void SetLevel(int loglevel);
   
    void log(std::string msg);
  

private:
    int loglevel_;
    Logger() {}
};

